<!-- 我的 -->
<template>
	<view class="mineContanin">
		<!-- <view :style="{ height: heightSystemss + 'px' }"></view> -->
		<!-- 蓝色背景 -->
		<view class="blueBackground"></view>

		<view class="tabList">
			<view class="avatarName">
				<block v-if="technicianDetails.authenticationNot!==3">
					<img class="avatar" @click="handleLogin()"
						:src="authorizationInformation.avatar?authorizationInformation.avatar:'/static/avatar.png'"
						alt="">
				</block>

				<block v-if="technicianDetails.authenticationNot==3">
					<img class="avatar" @click="handleLogin()"
						:src="technicianDetails.head?technicianDetails.head:'/static/avatar.png'" alt="">
				</block>

				<text class="nickName"
					v-if="technicianDetails.authenticationNot!==3">{{authorizationInformation.nickname?authorizationInformation.nickname:'-'}}</text>
				<text v-else
					class="nickName">{{technicianDetails.technicianName?technicianDetails.technicianName:'-'}}</text>
			</view>
			<!-- 列表 -->
			<view class="list flex-around">
				<view class=" flex-column width98">
					<view class="num">
						{{technicianDetails.authenticationNot==3?getSelectStatistics.comprehensiveScore?getSelectStatistics.comprehensiveScore:'0':'--'}}
					</view>
					<view class="text">
						综合评分
					</view>

				</view>
				<view class="numberServices flex-column width98">

					<view class="num">
						{{technicianDetails.authenticationNot==3?getSelectStatistics.serviceOrder?getSelectStatistics.serviceOrder:'0':'--'}}
					</view>
					<view class="text">
						服务数量
					</view>

				</view>
				<view class="positiveReviewRate flex-column width98">

					<view class="num">
						{{technicianDetails.authenticationNot==3?getSelectStatistics.positiveReviewRate?getSelectStatistics.positiveReviewRate:'0':'--'}}
					</view>
					<view class="text">
						好评率
					</view>

				</view>
				<view class="numberServices flex-column width98">

					<view class="num">
						{{technicianDetails.authenticationNot==3?getSelectStatistics.settledAmount?getSelectStatistics.settledAmount:'0':'--'}}
					</view>
					<view class="text">
						订单金额
					</view>
				</view>
			</view>
		</view>

		<!-- 任务中心 -->
		<view class="comprehensiveScore">
			<view class="card">
				<view class="header">
					<span class="headerTitle">任务中心</span>
					<span class="headerText">做完任务后才可以接单</span>
				</view>
				<!--任务中心列表  -->
				<view v-for="(item,i) in list" :key="i">

					<view v-if="item.serviceItemHiding" class=" comprehensiveScoreList flex-between">
						<view class="flex">
							<image class="avater" :src="item.img" mode=""></image>
							<view class="rightContent">
								<view class="authorizationTitle">
									{{item.text}}

								</view>
								<view class="authorizationText">
									{{item.title}}
								</view>

							</view>
						</view>

						<view v-if="item.disable" class="btnFinish flex">
							<span style="color:#D9D9D9;font-size: 14px;">已经完成</span>

						</view>
						<view v-else @click="toGo(item.url,item.pageName)" class="btnFinish flex">
							<span style="color:#FF466D;font-size: 14px;">去完成</span>

						</view>
					</view>
				</view>
				<!-- 	<view class="comprehensiveScoreList  flex-between">

					<view class="flex">
						<image class="avater" src="../../static/Vector-3.png" mode=""></image>
						<view class="rightContent">
							<view class="authorizationTitle">
								关注公众号
							</view>
							<view class="authorizationText">
								方便接收新订单/状态消息提醒
							</view>

						</view>
					</view>
					<view class="btnFinishs flex">
						<span style="color:#FF466D;font-size: 14px;">已经完成</span>
					</view>
				</view> -->

			</view>

		</view>
		<view class="bottom">

			<view class="card flex-align-center flex-wrap">
				<view v-if="item.serviceItemHiding" class="flex-column width25" @click="toGoBottom(item.url)"
					v-for="(item,i) in bottomList" :key="i">

					<image class="avater" :src="item.img" mode=""></image>
					<view class="rightContent">
						<view class="authorizationTitle">
							{{item.text}}
						</view>
					</view>

				</view>


			</view>



		</view>
		<!-- ‘冻结’ 弹框 -->
		<sunui-popup ref="popFreeze">
			<template v-slot:content>
				<view class="v-pop-freeze flex-column">
					<view class="v-title">提示</view>
					<view class="v-content">你的站点已冻结，请联系管理员</view>
				</view>
			</template>
		</sunui-popup>
		<sunui-popup ref="pop">
			<template v-slot:content>
				<view class="flex-column ">
					<image class="qrcode" :src="followThePublicAccount"></image>
					<button size="mini" @click="paste(followThePublicAccount)" type="" plain="true">保存图片到相册</button>
				</view>
			</template>
		</sunui-popup>
		<sunui-popup ref="technicianFreeze">
			<template v-slot:content>
				<view class="v-pop-freeze flex-column">
					<view class="v-title">提示</view>
					<view class="v-content">你的员工端被冻结，请联系管理员</view>
				</view>
			</template>
		</sunui-popup>


	</view>

</template>

<script>
	import {
		mapGetters,
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				list: [{
						img: '../../static/Group 3085.png',
						text: '手机授权',
						title: '以免客户无法联系到您，从而错失客户',
						url: '',
						pageName: "mobileAuthorization",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Vector-3.png',
						text: '关注公众号',
						title: '方便接收新订单/状态消息提醒',
						url: '',
						pageName: "identityAuthentication",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Group 3086.png',
						text: '认证信息',
						title: '资质与信息认证',
						url: '/pages/personalInformation/index',
						pageName: "personalInformation",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Group 3087.png',
						text: '签署协议',
						title: '在线签署，免责协议',
						url: '/pages/personalInformation/signtHheAgreement/index',
						pageName: "signtHheAgreement",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Vector-2.png',
						text: '设置服务区域',
						title: '设置服务城市和接单地址',
						url: '/pages/service-area/service-area',
						pageName: "serviceArea",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Vector.png',
						text: '设置服务项目',
						title: '设置服务项目方便平台推荐',
						url: '/pages/serviceItems/serviceItems',
						pageName: "serviceItems",
						disable: false,
						serviceItemHiding: true
					}
				],
				// 底部列表
				bottomList: [{
						img: '../../static/Group 3094.png',
						text: '员工信息',
						url: '/pages/personalInformation/index',
						pageName: "serviceItems",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Group 3095.png',
						text: '服务项目',
						url: '/pages/serviceItems/serviceItems',
						pageName: "serviceItems",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Frame-2.png',
						text: '服务区域',
						title: '设置服务项目方便平台推荐',
						url: '/pages/service-area/service-area',
						pageName: "serviceItems",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Frame-1.png',
						text: '用户评价',
						url: '/pages/personalInformation/userEvaluate/userEvaluate',
						pageName: "serviceItems",
						disable: false,
						serviceItemHiding: true
					},
					{
						img: '../../static/Group 3096.png',
						text: '意见反馈',
						url: '/pages/personalInformation/feedback/index',
						pageName: "serviceItems",
						disable: false,
						serviceItemHiding: true
					},
				],
				// 服务项目隐藏开关 1 隐藏 2 显示”

				title: 'Hello',

				getSelectStatistics: null,
				// 授权信息
				technicianDetail: null,
				followThePublicAccount: '',

				avatar: 'https://s3-alpha-sig.figma.com/img/dc62/a062/0d0034c670715af09a846d5a4269c318?Expires=1698019200&Signature=cZaZKk8UhKWtVrnI5w60l5MVUz1jbgzN3wa95Jf3vS5lcwTmQfV4AOif4Af5Cv6XVFqXx8hU5xBI~wfvSGklGfFJydYTPbgO~9-ll9Fn5cnLCdS34-vuiMUZdaCv1h6MXY0c0XB20X5wkU5xIxvcmIRqDPOhGhZnZw-86DKKApZyYRiwrpylPkTgUCQXGDYhjpbKl4l6VIIvE2EPubt6v~wFVIMLF1poL3xyhX2z4y90zf8ZLoW-sxxjgk1GIuEN7ZodS4ELlVtALzlR9FG5sG2eTeSXtHKKsdNtJZy3X3b3qbkt-2WrKRUldtS~S-dOZq6akrQuAIG8pvmX8xc4xg__&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4'
			}
		},
		onShow() {
			if (uni.getStorageSync('userId')) {

				this.createdgetSystemInfo();
				this.init()
				this.getSiteDomainID()
			} else {
				this.init()
			}
			this.queryOrderFn()
			// this.authorizationInformation=uni.getStorageSync('authorizationInformation')
		},
		onLoad() {
			this.init()
			// uni.setStorageSync('clearStoreage', true)

		},
		computed: {

			...mapGetters('user', ['taskCenter', 'technicianDetails', 'authorizationInformation']),

		},
		methods: {
			...mapMutations('user', ['uploadTaskCenter', 'technicianDetailsFn', 'uploadProgress',
				'authorizationInformationFn'
			]),
			async queryOrderFn(){
					console.log('===================进来了=================')
			
				if(this.technicianDetails.authenticationNot==3){
					const result = await this.$http.get({
						url: this.$api.getSelectTechnicianOrder,
						data: {
							page: 1,
							limit: 10,
							orderNumber:'',
							technicianEvaluationId: wx.getStorageSync('technicianId'), //技师id
							status: 1 //订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款
						}
					});
					if(result.code==200){
						this.orderCount=result.data.count
						if(this.orderCount>0){
							uni.setTabBarBadge({
								index:1,
								text:String(this.orderCount)
							})
						}
					}
				}
			
			},
			
			paste(followThePublicAccount) {
				console.log(followThePublicAccount)
				uni.downloadFile({
				  url: followThePublicAccount,
				  success: function (res) {
				    if (res.statusCode === 200) {
				      uni.saveImageToPhotosAlbum({
				        filePath: res.tempFilePath,
				        success: function () {
				          uni.showToast({ title: '保存相册成功' });
				        },
				        fail: function (err) {
				          console.log(err);
				          if (err.errMsg === 'saveImageToPhotosAlbum:fail auth deny') {
				            // 处理授权相册权限的逻辑
				          }
				        }
				      });
				    }
				  },
				  fail: function (err) {
				    console.log(err);
				  }
				});
			},

			async getSiteDomainID() {
				const url = this.$api.getSiteDomainName
				const siteDomainName = url.match(/^(?:https?:\/\/)?([^\/]+)/i)[1];
				console.log(siteDomainName)
				// uploadQualificationForm','uploadHealthCertificateForm','uploadAvatarForm','identityAuthenticationForm
				const result = await this.$http.get({
					url: this.$api.getSiteDomainName,
					data: {
						siteDomainName: siteDomainName // 站点域名(传值将https截取)
					}
				});

				if (result.code == 200) {
					// ‘冻结’弹出框

					if (result.data.siteStatus == '1') {
						this.openFreeze()
					} else {
						this.$refs.popFreeze.close()
					}

					this.siteId = result.data.id;

					uni.setStorageSync('siteId', this.siteId)
					console.log('根据站点域名查询站点result.', result);

				} else {
					this.$sun.toast(result.message)
				}
			},
			openFreeze() {
				console.log('进入‘冻结’弹出框');
				this.$refs.popFreeze.show({
					anim: 'center',
					shadeClose: false, //false使用户不能点击其它关闭页面
					topclose: false
				});
			},
			openTechnicianFreeze() {
				console.log('进入‘冻结’弹出框');
				this.$refs.technicianFreeze.show({
					anim: 'center',
					shadeClose: false, //false使用户不能点击其它关闭页面
					topclose: false
				});
			},
			async init(status = false) {
				if (this.technicianDetails.status == 3) {
					this.openTechnicianFreeze()
				} else {
					this.$refs.technicianFreeze.close()
				}
				const res = await this.$http.get({
					url: this.$api.getTechnicianId,
					data: {
						userId: this.uid = uni.getStorageSync('userId')
					}
				});
				if (this.technicianDetails?.authenticationNot == 3) {
					const result = await this.$http.get({
						url: this.$api.getSelectStatisticsMy,
						data: {
							technicianId: uni.getStorageSync('technicianId')
						}
					})
					if (result.code == 200) {
						console.log(result.data)
						this.getSelectStatistics = result.data
					}
				}

				const sitePlatformConfig = await this.$http.get({
					url: this.$api.sitePlatformConfig,
					data: {
						siteId: uni.getStorageSync('siteId')
					}
				});

				if (sitePlatformConfig.data.serviceItemHiding == 2) {

					this.bottomList[1].serviceItemHiding = true
					this.list[this.list.length - 1].serviceItemHiding = true


				} else if (sitePlatformConfig.data.serviceItemHiding == 1) {
					this.bottomList[1].serviceItemHiding = false
					this.list[this.list.length - 1].serviceItemHiding = false
				} else {
					this.bottomList[1].serviceItemHiding = true
					this.list[this.list.length - 1].serviceItemHiding = true
				};

				if (sitePlatformConfig.data) {
					this.followThePublicAccount = sitePlatformConfig.data.followThePublicAccount

				} else {
					this.$sun.toast('请在后台配置公众号图片~')
					return
				}



				if (res.code == 200) {
					console.log(res + '================')

					if (res.data) {

						uni.setStorageSync('technicianId', res?.data.id)

						if (uni.getStorageSync('technicianId')) {
							const technicianId = uni.getStorageSync('technicianId')
							const result = await this.$http.get({
								url: this.$api.queryTechnician + '/' + technicianId,
							});
							console.log(result)
							this.technicianDetail = result.data
							this.technicianDetailsFn(this.technicianDetail ? this.technicianDetail : '')

						}

					} else {

						if (uni.getStorageSync('clearStoreage') === false) {
							console.log('==================================================')
							uni.clearStorageSync()


							this.technicianDetailsFn({})
							this.authorizationInformationFn({})
							this.uploadTaskCenter({})
							this.uploadProgress({})
							uni.setStorageSync('clearStoreage', true)
						}


					}


					// uni.setStorageSync('technicianId',3)
				};
				console.log(this.authorizationInformation.phone)

				// 判断当前的手机号是否有值有就不需要授权手机号
				if (this.authorizationInformation.phone && !this.taskCenter?.name) {
					this.uploadTaskCenter({
						status: true,
						name: 'identityAuthentication'
					})
				};
				if (this.technicianDetails?.authenticationNot == 2) {
					// 首先 任务中心的需要全部都是已经完成的状态
					// 个人信息也是全部无法上传
					this.uploadTaskCenter({
						status: true,
						name: 'serviceItemsEnd'
					})

				};
				if (this.technicianDetails?.authenticationNot == 4) {
					for (let i = 0; i < this.list.length; i++) {
						this.list[i].disable = false
					}
					// 首先 任务中心的需要全部都是已经完成的状态
					// 个人信息也是全部无法上传
					console.log(this.authorizationInformation.phone, this.taskCenter?.name)
					if (!status) {
						if (JSON.parse(uni.getStorageSync('authorizationInformation')).phone) {
							// this.uploadTaskCenter({
							// 	status: true,
							// 	name: 'personalInformation'
							// })
							if (!(JSON.parse(uni.getStorageSync('taskCenter')).name == 'personalInformation')) {
								this.uploadTaskCenter({
									status: true,
									name: 'identityAuthentication'
								})
								this.uploadProgress({
									status: true,
									name: 'identityAuthentication'
								})
							}


						} else {
							this.handleLogin()
						}
					}
					// else {
					// 	this.uploadTaskCenter({
					// 		status: true,
					// 		name: 'mobileAuthorization'
					// 	})
					// }
				};
				if (this.technicianDetails?.authenticationNot == 3) {
					// 认证通过 状态变成编辑

					for (let i = 0; i < this.list.length; i++) {
						this.list[i].disable = true
					}

				} else {
					console.log('初始化========================')
					const index = this.list.findIndex(item => {
						return item.pageName == this.taskCenter?.name
					})
					this.currentIndx = index
					console.log(index)
					// 当前的状态 然后把前面的状态变为true
					if (index !== -1) {
						// -1 状态 有二种情况 
						for (let i = 0; i < this.currentIndx; i++) {
							this.list[i].disable = true
						}
					} else {
						console.log(this.taskCenter?.name)
						if (this.taskCenter?.name == 'serviceItemsEnd') {
							for (let i = 0; i <= this.list.length - 1; i++) {
								this.list[i].disable = true
							}
						}
					}
				}

			},
			createdgetSystemInfo() {
				let menuButtonObject = uni.getMenuButtonBoundingClientRect(); //获取菜单按钮（右上角胶囊按钮）的布局位置信息。坐标信息以屏幕左上角为原点。
				uni.getSystemInfo({
					//获取系统信息
					success: res => {
						let navHeight = menuButtonObject.height + (menuButtonObject.top - res
							.statusBarHeight) * 2; //导航栏高度=菜单按钮高度+（菜单按钮与顶部距离-状态栏高度）*2
						this.heightSystemss = navHeight;
					},
					fail(err) {
						console.log(err);
					}
				});
			},
			// 判断登录
			handleLogin() {
				this.uid = uni.getStorageSync('userId');
				if (this.uid) {
					return true;
				} else {
					uni.navigateTo({
						url: `/pages/login/login`
					});
					// 不在跳转到登录页面而是直接用弹框来显示
				}
			},
			// 跳转url
			toGoBottom(url) {
				if (this.handleLogin() && url) {
					if (this.technicianDetails.authenticationNot == 3) {
						this.$sun.navGo(url)
					} else if (this.technicianDetails.authenticationNot == 4) {
						this.$sun.toast(this.technicianDetails.reasonRejection ? '驳回原因:' + this.technicianDetails
							.reasonRejection : '审核失败请重新提交~')
					} else if (this.technicianDetails.authenticationNot == 2) {

						this.$sun.toast('当前正在审核中，请耐心等待~')
					} else {

						this.$sun.toast('未认证审核前，该功能暂不可用')
					}

				}

			},
			async toGo(url, pageName) {

				if (this.technicianDetails?.authenticationNot == 3) {
					if (this.handleLogin() && url) {
						this.$sun.navGo(url)

					}

				} else {
					console.log(this.taskCenter?.name)
					// z这里需要判断如果所有的都 禁用那么不能在点击上传
					const res = this.list.filter((item) => {
						return item.disable !== true
					})
					console.log(res)

					if (res.length) {
						if ((this.taskCenter.name ? this.taskCenter?.name : 'mobileAuthorization') == pageName) {
							if (this.handleLogin() && url) {
								console.log('================================')
								this.$sun.navGo(url)
							} else {
								if (this.taskCenter.name == 'identityAuthentication') {
									// 调用公众号图片
									const res = await this.$http.get({
										url: this.$api.gzh,
										data: {
											userId: this.uid = uni.getStorageSync('userId')
										}
									});
									console.log(res)

									// this.uploadTaskCenter({
									// 			status: true,
									// 			name: 'personalInformation'
									// 		})
									// 		this.init()
									// ========================

									if (res.code == 200) {

										// 判断当前是关注还是没有关注
										if (res.message == '已关注') {
											this.$sun.toast('关注成功')
											this.uploadTaskCenter({
												status: true,
												name: 'personalInformation'
											})
											this.init(true)

										}

									}
									if (res.code == 500 && res.message == '请先关注公众号') {
										this.$refs.pop.show({
											style: 'background-color:#fff;width:600rpx;border-radius:10rpx;padding:50rpx;',
											bottomClose: true,
											shadeClose: true,
											topclose: true
										});
										// this.$sun.toast(res.message)
									} else {
										this.$sun.toast(res.message)
									}
								}

							}
						} else {
							const selectPage = this.taskCenter.name ? this.taskCenter.name : 'mobileAuthorization'
							console.log(selectPage)
							if (selectPage == 'serviceItemsEnd') {
								if (this.handleLogin() && url) {
									this.$sun.navGo(url)
								}
							} else {
								if (selectPage == 'mobileAuthorization') {
									this.$sun.toast('请先完成手机号授权')
								} else if (selectPage == 'identityAuthentication') {
									this.$sun.toast('请先关注公众号')
								} else if (selectPage == 'personalInformation') {
									this.$sun.toast('请先完成资质与信息认证')
								} else if (selectPage == 'signtHheAgreement') {
									this.$sun.toast('请先完成入驻平台的协议隐私')
								} else if (selectPage == 'serviceArea') {
									this.$sun.toast('请先设置服务城市的区域')
								} else if (selectPage == 'serviceItems') {
									this.$sun.toast('请先设置服务项目')
								}
							}
						}
					} else {
						// 当所有填完以后就是真正审核中
						this.$sun.toast('正在审核请耐心等待')
					}
				}
			},
			onTabItemTap() {

				// 您点击了“导航”页...
			},
		}
	}
</script>
<style lang="less" scoped>
	.v-pop-freeze {
		background: #fff;
		width: 600rpx;
		border-radius: 20rpx;

		.v-title {
			width: 100%;
			text-align: center;
			border-bottom: 2rpx solid #e1e1e1;
			padding: 30rpx 0 20rpx;
			font-size: 30rpx;
			font-weight: bold;
		}

		.v-content {
			padding: 30rpx 0;
			text-align: center;
		}
	}

	.blueBackground {
		background-color: #2C7FFF;
		height: 120rpx;
		width: 100vw;

	}

	.qrcode {
		width: 580rpx;
		height: 580rpx;
	}

	.tabList {
		background-color: #fff;
		height: 124px;
		transform: translateY(-30px);
		border-radius: 20rpx 20rpx 0rpx 0rpx;

		.avatarName {
			transform: translateY(-60rpx);
			vertical-align: middle;
		}

		.avatar {

			width: 120rpx;
			height: 120rpx;
			border-radius: 120rpx;
			margin-left: 30rpx;
		}

		.nickName {
			margin-top: 20rpx;
		}

		.list {
			transform: translateY(-20rpx);

			.width98 {
				width: 156rpx;
				height: 100rpx;
			}

			.text {
				color: #999;
			}

			.num {
				margin-bottom: 22rpx;
				color: #000;
				font-size: 32rpx;
				font-weight: 600;
			}
		}
	}

	.comprehensiveScore {
		transform: translateY(-10px);

		.card {
			width: 708rpx;

			border-radius: 20rpx;
			background: #FFF;
			margin-left: 20rpx;
			padding: 22rpx;
			box-sizing: border-box;


			.headerTitle {
				color: #000;
				font-size: 32rpx;
				font-weight: 600;
				margin-right: 12rpx;
			}

			.headerText {
				font-size: 24rpx;
				color: #999;
			}

			.comprehensiveScoreList {
				height: 150rpx;
				border-bottom: 2rpx solid #F5F6FB;


				.avater {
					width: 56rpx;
					height: 56rpx;
					margin-right: 18rpx;

				}

				.rightContent {
					.authorizationTitle {
						color: #000;
						font-size: 28rpx;
						font-weight: 600;
						margin-bottom: 11rpx;
					}

					.authorizationText {
						color: #666;
						font-family: Inter;
						font-size: 24rpx;
					}

				}

				.btnFinish {
					width: 140rpx;
					height: 64rpx;
					border-radius: 76rpx;
					border: 2rpx solid #D9D9D9;

					background: #FFF;


				}

				.btnFinishs {
					width: 140rpx;
					height: 64rpx;
					border-radius: 76rpx;
					border: 2rpx solid #FF466D;

					background: #FFF;


				}

			}



		}
	}

	.bottom {

		width: 708rpx;

		border-radius: 20rpx;
		background: #FFF;
		margin-left: 20rpx;
		padding: 22rpx;
		box-sizing: border-box;

		.card {
			margin-top: 14rpx;

			.width25 {
				width: 25%;
				margin-bottom: 32rpx;

				.avater {
					width: 56rpx;
					height: 56rpx;
					margin-bottom: 24rpx;

				}
			}
		}

	}
</style>